﻿@model Pre.CRM.Models.CustomerContractModel
@{
    ViewBag.Title = "Contract";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<label class="lb_namecompany">@Model.Id</label>
    <a name="" type="button" value="" class="bt_black" width="26"  height="26" href='javascript:history.back();'></a>
    <div class="border_top" style="margin:15px 0px;clear:both"></div>
<form method="post" id="frmContract">
    <input type="hidden" name="agent" value="@Model.Agent"/>
    <input type="hidden" name="customer" value="@Model.Id"/>
    <input type="hidden" id="action" name="action" value=""/>
    <input type="hidden" id="service" name="service" value="1"/>
    <table style="font-size:14px; margin-top:5px" width="100%">
        <tr>
            <td colspan="2"><strong>Thông tin tên miền</strong></td>
        </tr>
        @foreach (var domain in Model.Domains)
        {
            <tr>
                <td>@domain</td>
                <td width="36" height="36" class="padding_left_10px float_right">
                    <img src="/Content/images/remove.png" onclick="SetDomain('@domain'); SetAction('DELETEDOMAIN');" alt="detail" width="36px" height="36px"/>
                </td>
            </tr>
        }
        <tr>
            <td><input id='domain' name="domain" type="text" class="input_add_domain" style="width:100%"/></td>
            <td width="36" height="36" class="padding_left_10px"><input name="" type="button" class="bt_add_domain" value="" onclick="SetAction('ADDDOMAIN');"/></td>
        </tr>
    </table>

    <table class="border_top" style="font-size:14px; margin-top:25px" width="100%">
        <tr>
            <td colspan="2"><strong>Thông tin template</strong></td>
        </tr>
        @foreach (var template in Model.Templates)
        {
            <tr>
                <td>@template</td>
                <td width="36" height="36" class="padding_left_10px float_right">
                    <img src="/Content/images/remove.png" onclick="SetTemplate('@template'); SetAction('DELETETEMPLATE');" alt="detail" width="36px" height="36px"/>
                </td>
            </tr>
        }
        <tr>
            <td><input id='template' name="template" type="text" class="input_add_domain" style="width:100%"/></td>
            <td width="36" height="36" class="padding_left_10px"><input name="" type="button" class="bt_add_domain" value="" onclick="SetAction('ADDTEMPLATE')"/></td>
        </tr>
    </table>

    <table class="border_top" style="font-size:14px; margin-top:25px" width="100%">
        <tr>
            <td colspan="4"><strong>Thông tin hợp đồng</strong></td>
        </tr>
        <tr>
            <td>Dịch vụ</td>
            <td>Đơn giá</td>
            <td>Lặp năm</td>
        </tr>
        @foreach (var service in Model.Contracts)
        {
            <tr>
                <td>@service.ServiceName</td>
                <td>@String.Format("{0:0,0}", service.Price)</td>
                <td>@service.Repeat</td>
                <td width="36" height="36" class="border_bottom padding_left_10px">
                    <img src="/Content/images/remove.png" onclick="SetService('@service.Id');SetAction('DELETESERVICE');" alt="detail" width="36px" height="36px"/>
                </td>
            </tr>
        }
        <tr>
            <td colspan="4">
                <table class="border_bottom" style="font-size:14px; margin-top:5px" width="100%">
                    <tr>
                        <td>Phí lần đầu:</td>
                        <td>@String.Format("{0:0,0}", Model.Contracts.Sum(e => e.Price))</td>
                    </tr>
                    <tr>
                        <td>Phí gia hạn:</td>
                        <td>@String.Format("{0:0,0}", Model.Contracts.Where(e => e.Repeat).Sum(e => e.Price))</td>
                    </tr>
                </table>
            </td>
        </tr>
        <tr>
            <td colspan="4">
                <table width="100%">
                    <tr>
                        <td width="50">Service:</td>
                        <td colspan="3">
                            <select class="input_contact" style="width:100%" id="listservice">
                                @foreach (var service in Model.Services)
                                {
                                    <option value="@service.Id">@service.Name</option>
                                }
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td>Price:</td>
                        <td><input name="price" class="input_contact" type="number"/></td>
                        <td>Repeat:</td>
                        <td>
                            <div class="frame_check_color" style="background:#66cc00">
                                <center><input name="repeat" type="checkbox"/></center>
                            </div>
                        </td>
                    </tr>
                </table>
                <center>
                    <input name="input" type="button" value="Add Service" onclick="SetAction('ADDSERVICE');" class="bt_cre_key margin_top_10px" style="width: 50%"/>
                </center>
            </td>
        </tr>
    </table>
</form>
<script language="javascript" type="text/javascript">
    function SetAction(value) {
        $('#action').val(value);
        $("#frmContract").submit();
    }

    function SetDomain(value) {
        $('#domain').val(value);
    }
    
    function SetTemplate(value) {
        $('#template').val(value);
    }

    function SetService(value) {
        $('#service').val(value);
    }

    $('#listservice').change(function () {
        var serviceid = $('#listservice').val();
        $('#service').val(serviceid);
    });
</script>
<div class="space"></div>

